package com.ellricky.baselib.adapter.course;


import android.app.Activity;
import android.view.View;
import android.widget.TextView;

import com.andr.common.ui.adapter.BaseRecyclerAdapter;
import com.andr.common.ui.adapter.SmartViewHolder;
import com.ellricky.baselib.R;
import com.ellricky.baselib.entity.course.CourseItemEntity;
import com.ellricky.baselib.ui.course.OnEditCourseListener;

public class CourseAdapter extends BaseRecyclerAdapter<CourseItemEntity> {

    private Activity activity;
    private boolean isEdit;
    private OnEditCourseListener listener;

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    public CourseAdapter(Activity activity, boolean isEdit, OnEditCourseListener listener) {
        super(R.layout.base_adapter_course);
        this.activity = activity;
        this.isEdit = isEdit;
        this.listener = listener;
    }


    @Override
    protected void onBindViewHolder(SmartViewHolder vh, final CourseItemEntity p1, int i) {
        vh.text(R.id.tvClassRoom, p1.getRoomName());
        vh.text(R.id.tvTime, p1.getClassTime());
        vh.text(R.id.tvCourseName, p1.getClassTypeName());

        // 编辑
        final TextView cbSel = vh.itemView.findViewById(R.id.cbSel);
        cbSel.setSelected(false);
        if (isEdit) {
            cbSel.setVisibility( View.VISIBLE);
            cbSel.setSelected(p1.isChecked());
            cbSel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    cbSel.setSelected(!cbSel.isSelected());
                    p1.setChecked(cbSel.isSelected());
                    listener.onEdit(p1);
                }
            });
        } else {
            cbSel.setVisibility(View.GONE);
        }
    }
}
